#include "pch.hpp"
#include "MouseHook.hpp"
#include "MouseHookHelper.hpp"

#include <boostext/smart_ptr.hpp>




extern boostext::smart_ptr<MouseHookHelper> m_mouseHook;




MouseHook::MouseHook(const MouseProc& mouseProc, HWND window)
	: m_mouseProc(mouseProc)
	, m_window(window)
{
	if(!m_mouseHook)
		m_mouseHook = boostext::smart_ptr<MouseHookHelper>(new MouseHookHelper());

	// Add ourselves to the list of dispatchers
	m_mouseHook->registerHook(this);
}
///////////////////////////////////////////////////////////////////////////////////////////////////

MouseHook::~MouseHook()
{
	// Remove ourselves from the list of dispatchers
	m_mouseHook->unregisterHook(this);

	if(!m_mouseHook->numHooks())
		m_mouseHook.release();
}
///////////////////////////////////////////////////////////////////////////////////////////////////




void MouseHook::mouseProc(WPARAM wParam, LPARAM lParam) const
{
	m_mouseProc(wParam, lParam);
}
///////////////////////////////////////////////////////////////////////////////////////////////////

HWND MouseHook::window() const
{
	return m_window;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
